//
//  ViewController.m
//  123345667
//
//  Created by 程旭 on 16/4/8.
//  Copyright © 2016年 程旭. All rights reserved.
//

#import "ViewController.h"

@interface ViewController () {
    
    UILabel *labelTime;
    
    NSTimer *timeNow;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor orangeColor];
    
    labelTime = [[UILabel alloc] initWithFrame:CGRectMake(60, 100, 200, 50)];
    
    labelTime.backgroundColor = [UIColor redColor];

    [self.view addSubview:labelTime];
    
    timeNow = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerFunc) userInfo:nil repeats:YES];
    
    
    
    //获取系统时间
    
    NSDate * senddate=[NSDate date];
    
    NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
    
    [dateformatter setDateFormat:@"HH:mm"];
    
    NSString * locationString=[dateformatter stringFromDate:senddate];
    
    NSLog(@"-------%@",locationString);
    
    //获取系统时间
    
    NSCalendar * cal=[NSCalendar currentCalendar];
    
    NSUInteger unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
    
    NSDateComponents * conponent= [cal components:unitFlags fromDate:senddate];
    
    NSInteger year=[conponent year];
    
    NSInteger month=[conponent month];
    
    NSInteger day=[conponent day];
    
    NSString * nsDateString= [NSString stringWithFormat:@"%4ld年-%2ld月-%2ld日",(long)year,(long)month,(long)day];
    
    NSLog(@"+++++++++++++%@",nsDateString);
    
}

- (void)timerFunc

{

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    
    
    [formatter setDateFormat:@"MM年dd月YY日 HH:mm:ss"];
    
    
    
    NSString *timestamp = [formatter stringFromDate:[NSDate date]];
    
    
    
    [labelTime setText:timestamp];//时间在变化的语句
    
    
    
    NSLog(@"%@",timestamp);
    
    
    
    
    
    
    
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
